/*
    XTU OJ: 1141
    by: fifth_light
*/

#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

int main(void) {
    int t;
    scanf("%d", &t);
    for(int i = 0; i < t; i++) {
        int64_t num;
        scanf("%" SCNd64, &num);
        if (num == 0) {
            puts("0");
            continue;
        }
        
        char result[4096];
        int base = 1;
        int add = 0;
        int i;
        for (i = 0; i < sizeof(result); i++, base *= 3) {
            if (base > num) {
                if (add == 1) {
                    result[i] = 1;
                } else {
                    i--;
                }
                break;
            }
            int n = num / base % 3 + add;
            add = 0;
            if (n == 2) {
                // 变Z
                n = 4;
                add = 1;
            } else if (n == 3) {
                n = 0;
                add = 1;
            }
            result[i] = n;
        }
        for (int j = i; j >= 0; j--) {
            switch (result[j]) {
                case 0:
                    putchar('0');
                    break;
                case 1:
                    putchar('1');
                    break;
                case 2:
                    putchar('2');
                    break;
                case 4:
                    putchar('-');
                    break;
            }
        }
        putchar('\n');
    }
    return 0;
}
